﻿namespace Pub.Class
{
    using System;
    using System.Runtime.CompilerServices;

    public static class DoubleExtensions
    {
        public static double IfEqual(this double obj, double value, double defaultValue)
        {
            if (obj != value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static double IfLessThan(this double obj, double value, double defaultValue)
        {
            if (obj >= value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static double IfLessThanOrEqual(this double obj, double value, double defaultValue)
        {
            if (obj > value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static double IfMoreThan(this double obj, double value, double defaultValue)
        {
            if (obj <= value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static double IfMoreThanOrEqual(this double obj, double value, double defaultValue)
        {
            if (obj < value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static double IfNotEqual(this double obj, double value, double defaultValue)
        {
            if (obj == value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static decimal PercentageOf(this double number, double percent)
        {
            return (decimal) ((number * percent) / 100.0);
        }

        public static decimal PercentageOf(this double number, int percent)
        {
            return (decimal) ((number * percent) / 100.0);
        }

        public static decimal PercentageOf(this double number, long percent)
        {
            return (decimal) ((number * percent) / 100.0);
        }

        public static decimal PercentageOf(this double number, float percent)
        {
            return (decimal) ((number * percent) / 100.0);
        }

        public static decimal PercentOf(this double position, double total)
        {
            decimal num = 0M;
            if ((position > 0.0) && (total > 0.0))
            {
                num = (((decimal) position) / ((decimal) total)) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this double position, int total)
        {
            decimal num = 0M;
            if ((position > 0.0) && (total > 0))
            {
                num = (((decimal) position) / total) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this double position, long total)
        {
            decimal num = 0M;
            if ((position > 0.0) && (total > 0L))
            {
                num = (((decimal) position) / total) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this double position, float total)
        {
            decimal num = 0M;
            if ((position > 0.0) && (total > 0f))
            {
                num = (((decimal) position) / ((decimal) total)) * 100M;
            }
            return num;
        }

        public static long Round(this double value)
        {
            if (value >= 0.0)
            {
                return (long) Math.Floor(value);
            }
            return (long) Math.Ceiling(value);
        }

        public static double Round(this double val, int decimalPoints)
        {
            return Math.Round(val, decimalPoints);
        }

        public static double Round2(this double val)
        {
            return Math.Round(val, 2);
        }

        public static string ToCurrency(this double value)
        {
            return value.ToString("N");
        }

        public static string ToRMB(this double value)
        {
            return ((decimal) value).ToRMB();
        }
    }
}

